package com.jett.mycloud.resp;

import lombok.Getter;

import java.util.Arrays;

@Getter
public enum ReturnCodeEnum {
    RC999("999","操作失败"),
    RC200("200","操作成功"),
    RC201("201","服务开启降级保护,请稍后再试"),
    RC202("202","热点参数限，请稍后再试"),
    RC203("203","系统规则不满足要求,请稍后再试!"),
    RC204("204","授权规则不通过,请稍后再试!"),
    RC403("403","无访问权限,请联系管吾员授权"),
    RC401("401","匿名用户访问无权限资源时的异常"),
    RC404("404","404页面无法找到"),
    RC500("500","系统异常，请稍后重试"),
    RC375("375","数学运算异常,请稍后重试"),
    INVALID_TOKEN("2001","访问令牌不合法"),
    ACCESS_DENIED("2003","没有权限访问该资源"),
    CLIENT_AUTHENTICATION_FAILED("1001","没有权限访问该资源"),
    USERNAME_OR_PASSWORD_ERROR("1002","客户端谁失败"),
    BUSINESS_ERROR("1004","业务逻辑异常"),
    UNSUPPORTED_GRANT_TYPE("1003","不支持的谁模式"),
    UNKNOWN_ERROR("9999","未知错误");

    private  final String code;
    private  final String message;
    ReturnCodeEnum(String code, String message){
        this.code=code;
        this.message=message;
    }


    public static ReturnCodeEnum getReturnCodeEnum(String code){
        return Arrays.stream(ReturnCodeEnum.values()).filter(x -> x.getCode().equalsIgnoreCase(code)).findFirst().orElse(UNKNOWN_ERROR);
    }

    public static void main(String[] args) {
        System.out.println(getReturnCodeEnum("9921").getCode());
        System.out.println(getReturnCodeEnum("9921").getMessage());
    }

}
